home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / asg.com / READDEMO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-07  |  3.9 KB  |  132 lines

  1. PROGRAM ReadDemo;
  2. USES
  3.  CRT,
  4.  AtSayGet,
  5.  BlueBag,
  6.  ReadASG;
  7.  
  8. TYPE
  9.  Info=RECORD
  10.   Address,
  11.   City  : STRING[20];
  12.   Phone : STRING[14];
  13.   CASE Business : BOOLEAN OF
  14.   False:(First : STRING[17];
  15.          Mid   : CHAR;
  16.          Last  : STRING[17]);
  17.   True: (Name  : STRING[26];
  18.          Years : WORD;
  19.          PorL  : REAL;
  20.          GorL  : INTEGER);
  21.  END; {variable record}
  22.  
  23. VAR
  24.  CA      : ARRAY[1..5,1..5] OF WORD;
  25.  AddInfo,
  26.  Cont,
  27.  More    : Boolean;
  28.  InfoFile:FILE OF Info;
  29.  A1,A2,
  30.  C1,C2   : WORD;
  31.  InfoRec : Info;
  32.  
  33. PROCEDURE BlankInfo;
  34. BEGIN
  35.  FillChar(InfoRec,SizeOf(InfoRec),0); InfoRec.Phone:='(   )    -    ';
  36. END;
  37.  
  38. PROCEDURE Init;
  39. {initialize 3 pages of ASG procs, assign & open data file, init vars}
  40. BEGIN
  41.  MakeASGHeapPage(1,6); {Page 1 has 6 fields t/b filled}
  42.  {set up ASG attributes}
  43.  OrgAttr:=7; SayAttr:=7; GetAttr:=113; EndAttr:=15;
  44.  WITH InfoRec DO
  45.  BEGIN
  46.   AddASGSL(1, 5,4,'First    ',@First,15);
  47.   AddASGCP(1, 5,5,'Initial  ',@Mid,'A');
  48.   AddASGSL(1, 5,6,'Last     ',@Last,15);
  49.   AddASGSL(1,50,6,'Address  ',@Address,20);
  50.   AddASGSL(1,50,8,'City     ',@City,20);
  51.   AddASGSP(1, 5,9,'Phone    ',@Phone,'(999) 999-9999');
  52.  END;
  53.  MakeASGHeapPage(2,4); {Page 2 has 4 fields t/b filled}
  54.  WITH InfoRec DO
  55.  BEGIN
  56.   AddASGSL(2, 5,6,'Name   ',@Name,25);
  57.   AddASGSL(2,50,6,'Address',@Address,20);
  58.   AddASGSL(2,50,8,'City   ',@City,20);
  59.   AddASGSP(2, 5,9,'Phone  ',@Phone,'(999) 999-9999');
  60.  END;
  61.  MakeASGHeapPage(3,3); {Page 3 has 3 fields t/b filled}
  62.  {set up new ASG attributes}
  63.  OrgAttr:=71; SayAttr:=71; GetAttr:=112; EndAttr:=79;
  64.  WITH InfoRec DO
  65.  BEGIN
  66.   AddASGW (3,2,2,'Years in business.......',@Years,2);
  67.   AddASGR (3,2,3,'Profit/Loss this year  $',@PorL,10,2);
  68.   AddASGI (3,2,4,'Gain/Loss of employees..',@GorL,4);
  69.  END;
  70.  TextAttr:=7; OrgAttr:=7; SayAttr:=7; GetAttr:=113;
  71.  AddInfo:=False; Cont:=True; More:=True; FillChar(CA,SizeOf(CA),0);
  72.  Assign(InfoFile,'READDEMO.TST');
  73.  IF OnFile('READDEMO.TST') THEN RESET(InfoFile) ELSE
  74.  BEGIN
  75.   REWRITE(InfoFile); AddInfo:=True;
  76.  END;
  77. END;
  78.  
  79. BEGIN
  80.  Init;
  81.  REPEAT
  82.   ClrScr;
  83.   AtSay(5,1,'The full screen can be edited using cursor & tab keys.');
  84.   IF NOT AddInfo THEN
  85.   BEGIN {editing a file record}
  86.    BlankInfo; READ(InfoFile,InfoRec);
  87.    IF EOF(InfoFile) THEN AddInfo:=True;
  88.    SEEK(InfoFile,FilePos(InfoFile)-1);
  89.   END
  90.   ELSE
  91.   BEGIN
  92.    BlankInfo;
  93.    AtSayGetBoolean(5,3,'Adding a business record?',InfoRec.Business);
  94.   END;
  95.   IF InfoRec.Business THEN
  96.   BEGIN
  97.    ReadPage(2);
  98.    OpenWindow(20,5,60,11,White,Red,1,' FINANCIAL INFORMATION ');
  99.    ReadPage(3);
  100.    CloseWindow; {financial information}
  101.    SayAttr:=7; OrgAttr:=7;
  102.   END
  103.   ELSE ReadPage(1);
  104.   WRITE(InfoFile,InfoRec);
  105.   IF AddInfo THEN AtSayGetBoolean(2,24,'Add a record?',More)
  106.    ELSE AtSayGetBoolean(2,24,'Edit next record?',More);
  107.   IF NOT More THEN
  108.   BEGIN
  109.    CLOSE(InfoFile); Cont:=False;
  110.   END;
  111.  UNTIL NOT Cont;
  112.  
  113.  {notice how a page is reused and dynamicaly re-built in the following code}
  114.  FOR C1:=3 DOWNTO 1 DO FreeASGHeapPage(C1);
  115.  A1:=0; A2:=0; C1:=0; C2:=0; FillChar(CA,SizeOf(CA),0);
  116.  ClrScr;
  117.  WRITELN('The following demonstrates how to reuse an ASG Page. It also gives an example');
  118.  WRITELN('of how to add fields to a page at runtime depending upon variable criteria.');
  119.  {re-set ASG attributes}
  120.  OrgAttr:=7; SayAttr:=7; GetAttr:=113; EndAttr:=15;
  121.  AtSayGetWordRange(1,4,'Enter a number of columns from 2 to 5:',C2,1,2,5);
  122.  AtSayGetWordRange(1,5,'Enter a number of rows from 2 to 5   :',C1,1,2,5);
  123.  MakeASGHeapPage(1,C1*C2); {you will add Rows*columns of fields to the page}
  124.  FOR A1:=1 TO C1 DO FOR A2:=1 TO C2 DO
  125.   IF A2=1 THEN AddASGW(1,1,A1+9,'Enter numbers',@CA[A1,A2],2)
  126.   ELSE AddASGW(1,((A2-1)*10+15),A1+9,'',@CA[A1,A2],2);
  127.  AtSay(15,8,'The screen below can be edited using cursor & tab keys.');
  128.  ReadPage(1);
  129.  FreeASGHeapPage(1); {this isn't really necessary as ReadASG frees all pages
  130.                       as part of its exit code}
  131.  AtSay(15,24,'Read ME.2');
  132. END.